package cn.beforedark.yygh.hosp.controller.api;


import cn.beforedark.yygh.common.result.R;
import cn.beforedark.yygh.hosp.service.HospitalSetService;
import cn.beforedark.yygh.hosp.service.ScheduleService;
import cn.beforedark.yygh.model.hosp.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
public class ApiScheduleController {

    @Autowired
    private HospitalSetService hospitalSetService;

    @Autowired
    private ScheduleService scheduleService;


    /**
     * 上传排班
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/saveSchedule")
    public R saveSchedule(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        scheduleService.save(map);
        return R.ok200();
    }

    /**
     * 分页查询排班
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/schedule/list")
    public R getScheduleList(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        Page<Schedule> page = scheduleService.getScheduleList(map);
        return R.ok200Data(page);
    }


    /**
     * 删除排班
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/schedule/remove")
    public R removeSchedule(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        scheduleService.remove(map);
        return R.ok200();
    }


}
